<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>创建对象</title>
    <script>
        // 1.字面量创建对象
        /* var obj = {
            name: '可可',
            type: '阿拉斯加犬',
            age: 5,
            color: 'red',
            habit: function() {
                console.log('back' + 'showFilm');
            }
        } */

        // 2.利用new Object创建对象
        /* var obj = new Object();
        obj.name = '鸣人';
        obj.sex = '男';
        obj.age = 19;
        obj.skill = function() {
            console.log('影分身术');
        } */

        // 3.构造函数创建对象
        /*  function Star(name, sex, age) {
             this.name = name;
             this.sex = sex;
             this.age = age;
             this.sing = function(song) {
                 console.log(song);
             }
         }
         // 调用：
         var a = new Star('丘吉尔', '男', 18);
         console.log(a.name);
         console.log(a['sex']);
         a.sing('啦啦啦'); */

        // 4.构造函数创建对象的案例
        function wzry(username, type, blood) {
            this.name = username;
            this.type = type;
            this.blood = blood;
            this.attack = function(attack) {
                console.log(attack);
            }
        }
        var lp = new wzry('廉颇', '力量型', '500血量');
        console.log(lp.name);
        console.log(lp['blood']);
        lp.attack('近战')
        var hy = new wzry('后羿', '射手型', '1000血量')
        console.log(hy.name);
        console.log(hy['type']);
        hy.attack('射手')
        console.log(hy);
    </script>
</head>

<body>

</body>

</html>